Developing Enterprise iOS Applications by James Turner

Developing Enterprise iOS Applications by James Turner

Author:James Turner
Language: eng
Format: mobi, pdf
Tags: COMPUTERS / Programming / Apple Programming
ISBN: 9781449314415
Publisher: O'Reilly Media
Published: 2011-08-25T22:00:00+00:00


Example 4-6. The getSingleStringValue method

-(id) getSingleStringValue:(DDXMLElement *) element

xpath:(NSString *) xpath {

NSError *error = nil;

NSArray *vals = [element nodesForXPath:xpath error:&error];

if (error != nil) {

return nil;

}

if ([vals count] != 1) {

return nil;

}

DDXMLElement *val = [vals objectAtIndex:0];

return [val stringValue];

}

Basically, the method takes the root element for the extraction, and a relative or absolute XPath expressing as a string. It gets the array of matching elements, makes sure there wasn’t an error (such as an invalid XPath string), and if it gets back exactly one element in the array, returns it.

Once I have the dictionary, I iterate over the temperature data, grabbing attributes and element values as appropriate, then use the diction to find the time associated with the reading. Finally, I dump the data out to the log, resulting in this kind of output:

Type: maximum, Units: Fahrenheit

2011-11-16T07:00:00-05:00, Daily Maximum Temperature = 58



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.